<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <HomeGood v-for="itm in arr" :key="itm.id" :arr="itm"/>
  </div>
</template>
<script>
import { computed, onMounted, ref } from 'vue'
import HomeGood from '@/views/Home/components/home-goods'
import { findHotGoods } from '@/api/goods'
import { useRoute } from 'vue-router'
export default {
  name: 'HomeGoods',
  components: {
    HomeGood
  },
  props: {
    type: {
      type: Number,
      default: 1
    }
  },
  setup (props) {
    const titleObj = { 1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜' }
    const title = computed(() => {
      return titleObj[props.type]
    })
    const route = useRoute()
    const arr = ref([])
    async function getObj () {
      const res = await findHotGoods({ id: route.params.id, type: props.type })
      arr.value = res.result
    }
    onMounted(() => {
      getObj()
    })
    return { title, arr }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
